package com.rem.concurrency.multithreading.state;

/**
 * 守护线程
 * @author Rem
 * @date 2021-03-04
 */

public class ThreadDaemon {

    public static void main(String[] args) {
        Gad gad = new Gad();
        You you = new You();

        Thread thread = new Thread(gad);
        //设置为守护线程
        thread.setDaemon(true);
        thread.start();

        new Thread(you).start();
    }

}


class Gad implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.err.println("protect you...");
        }
    }
}

class You implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 300; i++) {
            System.err.println("live...");
        }
    }
}


